package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Study;
import com.ruoyi.system.service.IStudyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 每日一题Controller
 * 
 * @author 寒
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/study/study")
public class StudyController extends BaseController
{
    @Autowired
    private IStudyService studyService;

    /**
     * 查询每日一题列表
     */
    @PreAuthorize("@ss.hasPermi('study:study:list')")
    @GetMapping("/list")
    public TableDataInfo list(Study study)
    {
        startPage();
        List<Study> list = studyService.selectStudyList(study);
        return getDataTable(list);
    }

    /**
     * 导出每日一题列表
     */
    @PreAuthorize("@ss.hasPermi('study:study:export')")
    @Log(title = "每日一题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Study study)
    {
        List<Study> list = studyService.selectStudyList(study);
        ExcelUtil<Study> util = new ExcelUtil<Study>(Study.class);
        util.exportExcel(response, list, "每日一题数据");
    }

    /**
     * 获取每日一题详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:study:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(studyService.selectStudyById(id));
    }

    /**
     * 新增每日一题
     */
    @PreAuthorize("@ss.hasPermi('study:study:add')")
    @Log(title = "每日一题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Study study)
    {
        return toAjax(studyService.insertStudy(study));
    }

    /**
     * 修改每日一题
     */
    @PreAuthorize("@ss.hasPermi('study:study:edit')")
    @Log(title = "每日一题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Study study)
    {
        return toAjax(studyService.updateStudy(study));
    }

    /**
     * 删除每日一题
     */
    @PreAuthorize("@ss.hasPermi('study:study:remove')")
    @Log(title = "每日一题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(studyService.deleteStudyByIds(ids));
    }
}
